﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Globalization;

namespace Medianamik.UI.Lock
{
    public static class LockContext
    {

        public static Transaction CurrentTransaction
        {
            get
            {
                return InitFromCookie();
            }
        }

        private static Transaction InitFromCookie() 
        {
            if(HttpContext.Current == null ) { return null;}
            HttpCookie c  = HttpContext.Current.Request.Cookies[Transaction.COOKIE_NAME];
            if (c == null) { return null; }
            else
            {
                string idStr = c["uId"];
                Guid id;

                if (Core.Sugar.StringHelper.IsGuid(idStr, out id))
                {
                    return new Transaction(id);
                }
                return null;
            }
        }
    }
}
